package Test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import Config.Configure;
import Config.GlobalLog;
import EurekaAnalyzer.IDInformation;
import Statistics.IDGraph;
import Statistics.IDGraphGlobalProperty;
import Statistics.IDGraphNode;
import Statistics.IDGraphToJungGraph;
import Store.StoreManager;
import EurekaProcessor.Clusterer;
import java.util.Scanner;

public class TestClusterer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HashMap<String, IDGraphNode> map = new HashMap<String, IDGraphNode>();
		FileReader fin = null;
		try {
			fin = new FileReader("D:/workspace/amoamo/trunk/TestData/TestCluster/graph1.txt");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("FileNotFound");
			e.printStackTrace();
		}
		Scanner sc = new Scanner(fin);
		int n = sc.nextInt();
		int m = sc.nextInt();
		IDGraphNode[] nodes = new IDGraphNode[n+1];
		for(int i = 0; i < n; i++)
			nodes[i] = new IDGraphNode(Integer.toString(i));
		for(int i = 0; i < m; i++)
		{
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a + " " + b);
			nodes[a].GetOutEdges().put(Integer.toString(b), 1);
			nodes[b].GetInEdges().put(Integer.toString(a), 1);
		}
		IDGraph graph = new IDGraph();
		for(int i = 0; i < n; i++)
			map.put(Integer.toString(i), nodes[i]);
		graph.SetNodeMap(map);
		
		Set<Set<String>> clusters = Clusterer.HierarchicalClusteringFast(graph, 3);
		List<Set<String>> list = new ArrayList<Set<String>>(clusters);
		for(int i = 0; i < clusters.size(); i++)
		{
			System.out.print("Set " + i + ": ");
			List<String> members = new ArrayList<String>(list.get(i));
			for(int j = 0; j < members.size(); j++)
				System.out.print(members.get(j) + " ");
			System.out.println();
		}
		
	}

}
